package com.ivideo.home.widget

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.bawei.library_widget.VerticalTextview
import com.bawei.library_widget.databinding.ViewXiguatitlebarBinding


/**
 * @author hahajing 企鹅：444511958
 * @createDate 2022/4/19 14:21
 * @description
 *
 * @updateUser hahajing
 * @updateDate 2022/4/19 14:21
 * @updateRemark
 *
 * @version 1.0.0
 */
class XiGuaTitleBar @JvmOverloads constructor(context: Context, attributes: AttributeSet) : LinearLayout(context,attributes){
    private val binding: ViewXiguatitlebarBinding = ViewXiguatitlebarBinding.inflate(LayoutInflater.from(context),this,true)

    init {
        removeAllViews()
        addView(binding.root)


        binding.vtViewXiguatitlebarTxt.setText(19.0f, 5, Color.LTGRAY) //设置属性,具体跟踪源码

        binding.vtViewXiguatitlebarTxt.setTextStillTime(3000) //设置停留时长间隔

        binding.vtViewXiguatitlebarTxt.setAnimTime(300) //设置进入和退出的时间间隔

        //对单条文字的点击监听
        binding.vtViewXiguatitlebarTxt.setOnItemClickListener(VerticalTextview.OnItemClickListener {
            callback?.onClick(it)
        })
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
//        BadgeUtil.Badge(context,binding.ivViewXiguatitlebar,0)
        binding.vtViewXiguatitlebarTxt.startAutoScroll()
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        binding.vtViewXiguatitlebarTxt.stopAutoScroll()
    }

    /**
     * 设置数据源
     */
    fun setDataSource(list:MutableList<String>){
        binding.vtViewXiguatitlebarTxt.setTextList(list as ArrayList<String>?)
    }

    private var callback:TitleBarClickCallback?=null

    /**
     * 设置点击回调
     */
    fun setOnClickCallback(_callback:TitleBarClickCallback){
        callback=_callback
    }

    interface TitleBarClickCallback{
        fun onClick(index:Int)
    }
}